<template>
	<view>
		<view class="list" v-for="item in list" :key="item.id">
			<view class="left-img">
				<view class="img">
					<img :src="item.cover" alt="">
				</view>
			</view>
			<view class="item">
				<view class="header">
					<span>{{item.title}}</span>
				</view>
				<view class="footer">
					<view class="listt">
						<span>￥{{item.price}}</span>
						<span>￥{{item.t_price}}</span>
					</view>
					<view class="p" @click="tiao(item.id)">{{item.sub_count}}人订阅
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		booklist
	} from "@/api/user.js"
	export default {
		data() {
			return {
				queryModel: {
					page: 2,
					limit: 10
				},
				count: 0,
				list: []
			}
		},
		onLoad() {
			this.getdata()
		},
		onPullDownRefresh: function() {
			//注意数据最好清空下，刷新后只展示第1页的内容
			this.list = []
			this.obj.page = 1
			setTimeout(() => {
				uni.stopPullDownRefresh()
				this.getdata();
			})
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			console.log('到底了');
			console.log(this.queryModel.page, this.count);
			if (this.queryModel.page >= this.count) {
				wx.showToast({
					title: '到最后一页了',
				})
			} else {
				this.queryModel.page++
				this.getdata()

			}
		},
		methods: {
			//跳到详情
			tiao(type){
				this.$router.push({
					path:"/pages/book-detail/book-detail",
					query:{
						type:type
					}
				})
			},
			async getdata() {
				const res = await booklist(this.queryModel)
				console.log(res);
				if (res.code == "20000") {
					// this.list=res.data.rows
					this.count = Math.ceil(res.data.count = res.data.rows)
					this.list = [...this.list, ...res.data.rows]
				}
				console.log(this.list);
			}
		}
	}
</script>

<style scoped lang="scss">
	* {
		box-sizing: border-box;
	}

	.list {
		width: 750rpx;
		height: 290rpx;
		background-color: white;
		display: flex;

		.item {
			width: 500rpx;
			height: 290rpx;
			background-color: white;

			.header {
				width: 500rpx;
				height: 220rpx;
				background-color: white;

				span {
					display: inline-block;
					padding-left: 20rpx;
					padding-top: 20rpx;
					font-size: 38rpx
				}
			}

			.footer {
				width: 500rpx;
				height: 70rpx;
				background-color: white;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.p {
					width: 90rpx;
					height: 30rpx;
					line-height: 30rpx;
					margin-right: 40rpx;
					border-width: 1px;
					text-align: center;
					border-style: solid;
					border-color: #dee2e6;
					border-radius: 12rpx;

				}

				.listt {
					span:nth-child(1) {
						font-size: 38rpx;
						color: #DC3545;
					}

					span:nth-child(2) {
						font-size: 27rpx;
						color: #a9a5a0;
					}
				}

			}
		}

		.left-img {
			width: 250rpx;
			height: 290rpx;
			background-color: white;
			display: flex;
			align-items: center;
			justify-content: center;

			.img {
				width: 230rpx;
				height: 260rpx;
				background-color: blue;

				img {
					width: 230rpx;
					height: 260rpx;
				}
			}

		}
	}
</style>
